//@author A0096794H
#include "KeyboardWarrior.h"

void KeyboardWarrior::run()
{
	std::string userCommand, result, displayContents;
	CommandType command;
	display(MESSAGE_WELCOME);
	try{
	Logic::initiate(displayContents);
	}
	catch(string &e)
	{
		display(e);
	}
	display(displayContents);
	
	do
	{
		display(MESSAGE_PROMPT);
		userCommand = getUserCommand();
		command = Logic::executeCommand(userCommand, result);
		system("cls");
		Logic::displayTask(displayContents);
		display(command, result, displayContents);
	} while (command != EXIT);
	display(MESSAGE_EXIT);
}


//@author A0105566E
void KeyboardWarrior::display(CommandType command, std::string message, std::string show)
{
	switch (command) {
	case DISPLAY:
		displayResults(message);
		break;
	case ADD: 
	case SEARCH:
	case DELETE:
	case UPDATE:
	case UNDO:
	case REDO:
	case MARK:
	case UNMARK:
	case SUMMARY:
		displayResults(show);
		display(message);
		break;
	case EXIT:
		break;
	case INVALID:
	default:
		display(MESSAGE_INVALID_COMMAND);
	}
}

void KeyboardWarrior::displayResults(std::string results){
	cout << MESSAGE_DISPLAY << results << endl;
}

std::string KeyboardWarrior::getUserCommand()
{
	std::string command;
	getline(cin, command);
	return command;
}

void KeyboardWarrior::display(std::string message)
{
	cout << message;
}